package com.doit.day05

import scala.collection.mutable.ListBuffer

object _04_list {
  def main(args: Array[String]): Unit = {
    //不可变list ==》 Array   list里面的元素不能改
    val list: List[Int] = List(1, 2, 3, 4, 4, 3, 2)
    val ints: List[Int] = list.:+(10)
    println(ints)

    val ints1: List[Int] = list.::(100)//List(100, 1, 2, 3, 4, 4, 3, 2)
    val ints2: List[Int] = 100 :: list  //List(100, 1, 2, 3, 4, 4, 3, 2)

    //Nil 空列表  List()==> list 的类型
    val list1: List[Int] = 10 :: 20 :: 30 :: 40 :: Nil
    val list2: List[Int] = Nil.::(4).::(3).::(2).::(1)
    println(list1)//List(1, 2, 3, 4)

    val ints3: List[Int] = list2.:::(list1)//List(10, 20, 30, 40, 1, 2, 3, 4)
    val ints4: List[Int] = list1 ::: list2
    println(ints3)
    //获取元素  对应索引的元素
    println(list1(1))

    //他的值不能够修改
//    list1(1) = 100 //这个值不能被修改

    val ints5: List[Int] = list1.drop(1)
    println(ints5)//List(20, 30, 40)


    //可变集合
    val ints6: ListBuffer[Int] = new ListBuffer[Int]()
    ints6.append(1,2,3,4)
    //在原来的toString方法之后加上了一个传进去的值Hello
    val str: String = ints6.+("hello")
    println(str)
    //和ArrayBuffer一样


  }
}
